package cn.geminis.fabric.service.service;

import lombok.RequiredArgsConstructor;
import org.hyperledger.fabric.gateway.Gateway;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * @author puddi
 */
@Service
@RequiredArgsConstructor
public class ChaincodeService {

    private final Gateway gateway;

    public String get(String channel, String chaincode, String id) throws Exception {
        var network = gateway.getNetwork(channel);
        var contract = network.getContract(chaincode);
        var value = contract.evaluateTransaction("get", id);
        return new String(value, StandardCharsets.UTF_8);
    }

}
